package com.doit.hbase.client;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

/**
 * @DATE 2021/12/13/11:15
 * @Author MDK
 * @Version 2021.2.2
 * table.delete(delete)  如果delete对象中没有进行其他的设置 直接删除行数据
 * delete.addColumn("cf".getBytes() ,"job".getBytes()) ;  删除指定的属性列
 * delete.addFamily("cf2".getBytes()) ; 删除指定的列族数据
 *
 **/
public class C03_Delete {
    public static void main(String[] args) throws Exception {
        //获取连接
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
        Connection conn = ConnectionFactory.createConnection(conf);

        //获取操作对象
        Table table = conn.getTable(TableName.valueOf("tb_teacher"));
        Delete delete = new Delete("rk002".getBytes());
        delete.addColumn("cf".getBytes(),"name".getBytes());  //删除name单元格
        delete.addColumn("cf".getBytes(),"job".getBytes());  //不存在job属性不删除,不报错
//        delete.addFamily("cf2".getBytes());   //不存在cf2列族则报错
        table.delete(delete);
        //关闭资源
        table.close();
        conn.close();
    }
}
